package com.demo.livemanagement.livedelayqueue;

import org.apache.log4j.Logger;

import com.demo.livemanagement.service.LiveService;
import com.demo.utils.applicationcontext.SpringContextUtil;

/**
 * 直播结束自动监控线程
 * 
 * @author Rose 2017年11月7日
 */
public class LiveDelayTimeoutThread implements Runnable {

	private static final Logger LOGGER = Logger.getLogger(LiveDelayTimeoutThread.class);

	@Override
	public void run() {

		LOGGER.info(" ====live delay thread start success====");

		LiveService liveService = (LiveService) SpringContextUtil.getBean(LiveService.class);
		@SuppressWarnings("unchecked")
		LiveDelayQueue<LiveDelayInfo> qu = LiveDelayQueue.getInstance();
		while (true) {
			LiveDelayInfo obj = null;
			try {
				obj = qu.take();
				LOGGER.info(obj);
				liveService.timerUpdateLive(obj.getLiveId());
				LOGGER.info("直播过期自动处理成功，直播主键是：=" + obj.getLiveId());
			} catch (InterruptedException e) {
				LOGGER.error("直播过期处理线程出错：", e);
				e.printStackTrace();
			}
		}
	}

}
